#ifndef FRAME_H
#define FRAME_H
using u_char = unsigned char;
using u_short = unsigned short;
using u_int = unsigned int;
/* 4 bytes IP address */
typedef struct ip_address{
    u_char byte1;
    u_char byte2;
    u_char byte3;
    u_char byte4;
}ip_address;

/* IPv4 header */
typedef struct ip_header{
    u_char  ver_ihl; // Version (4 bits) + IP header length (4 bits)
    u_char  tos;     // Type of service
    u_short tlen;    // Total length
    u_short identification; // Identification
    u_short flags_fo; // Flags (3 bits) + Fragment offset (13 bits)
    u_char  ttl;      // Time to live
    u_char  proto;    // Protocol ICMP为1，TCP为6，UDP为17
    u_short crc;      // Header checksum
    ip_address  saddr; // Source address
    ip_address  daddr; // Destination address
    u_int  op_pad;     // Option + Padding
}ip_header;

/* UDP header*/
typedef struct udp_header{
    u_short sport; // Source port
    u_short dport; // Destination port
    u_short len;   // Datagram length
    u_short crc;   // Checksum
}udp_header;

/* TCP header*/
typedef struct tcp_header{
    u_short sport; // Source port
    u_short dport; // Destination port
    u_int seq; // 序号
    u_int ack; // 确认号
    u_short flags; // 4位头部长度+6保留位+6位标识符
    u_short winS; // 窗口大小
    u_short crc;   // Checksum
    u_short pointer;   // 紧急指针
    u_int  op_pad;     // Option + Padding
}tcp_header;


#endif // FRAME_H
